package com.orm.handler;

import java.sql.*;
import java.time.LocalDate;


public class LocalDateTypeHandler extends BaseTypeHandler<LocalDate>{
	
	@Override
	public void setNotNullParameter(PreparedStatement ps, int i, LocalDate parameter, JDBCType jdbcType) throws SQLException {
		ps.setDate(i, Date.valueOf(parameter));
	}
	
	@Override
	public LocalDate getNullableResult(ResultSet rs, String columnName) throws SQLException {
		return getLocalDate(rs.getDate(columnName));
	}
	
	@Override
	public LocalDate getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return getLocalDate(rs.getDate(columnIndex));
	}
	
	public LocalDate getLocalDate(Date date){
		if(date != null){
			return date.toLocalDate();
		}
		return null;
	}
}
